import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedSize;
    private static final int DEFAULT_SISE = 10;
    public MyStack() {
        elem = new int[DEFAULT_SISE];
    }

    public void push (int val) {
        if (isFull()) {
            elem = Arrays.copyOf(elem,elem.length * 2);
        }
        elem[usedSize] = val;
        usedSize++;
    }

    public boolean isFull () {
        return usedSize == elem.length;
    }

    public int pop () {
        if (isEmpty()) {
            throw new EmptyException("栈为空");
        }
        int val = elem[usedSize - 1];
        usedSize--;
        return val;
    }

    public int peek () {
        if (isEmpty()) {
            throw new EmptyException("栈为空");
        }
        return elem[usedSize - 1];
    }

    public boolean isEmpty() {
        return usedSize == 0;
    }

}

